package com.kailing.bootbatch.piliang;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;

/**
 * <h3>springboot_batch_jdbc</h3>
 * <p>定时运行任务</p>
 *
 * @author : hduong
 * @version : 1.0
 * @date : 2019-12-06 17:29
 **/
@Configuration
public class RunPiLiangFileJob {

    @Autowired
    private JobLauncher jobLauncher;

    @Autowired
    @Qualifier("piLiangJob")
    private Job job;

    @Scheduled(cron = "0/20 * * * * ?")
    public void runJob() {
        String fileName = "customer.txt";
        JobParameters jobParameters = new JobParametersBuilder()
                .addDate("date", new Date())
                .addString("fileName", fileName)
                .toJobParameters();
        try {
            jobLauncher.run(job, jobParameters);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("执行任务失败...............");
        }
        System.out.println("...........................");
    }

}
